package tool.json

import androidx.compose.runtime.mutableStateOf
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.*



class JsonToKotlinState {
    var kotlinOutput = mutableStateOf("")

    fun convert(json: String) {
        val res = kotlin.runCatching {
            Json.parseToJsonElement(json)
        }
        if (res.isFailure) {
            kotlinOutput.value = "解析 Json 失败"
            return
        }
        val jsonElement = res.getOrThrow()
        kotlinOutput.value = jsonToKotlin(jsonElement)
    }

}